package com.yss.reportworld.domain.rule;

import com.yss.common.core.enums.BaseEnum;
import com.yss.common.core.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;


@Getter
@AllArgsConstructor
public enum FuncParamEnum implements BaseEnum<Integer> {

    STRING(0, "String"),
    INTEGER(1, "Integer"),
    DOUBLE(2, "Double"),
    DATE(3, "Date"),
    TIME(4, "LocalTime"),
    DATETIME(5, "LocalDateTime"),
    OBJECT(6, "Object"),
    BOOLEAN(7, "Boolean"),
    COLLECTION(8, "List");

    private Integer code;
    private String desc;

    public static FuncParamEnum getEnum(Integer code) {
        return Arrays.stream(values()).filter(b -> b.code == code).findFirst().orElse(null);
    }

    public static String getEnumDesc(Integer code) {
        FuncParamEnum e = getEnum(code);
        return e != null ? e.desc : null;
    }

    public static Integer getEnumCode(String desc) {
        for (FuncParamEnum paramEnum : FuncParamEnum.values()) {
            if (StringUtils.isNull(paramEnum)) {
                continue;
            }
            if (paramEnum.getDesc().equals(desc)) {
                return paramEnum.getCode();
            }
        }
        return null;
    }
}
